﻿using AvalonDock.Layout;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using SqLiteEditor.Helper;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;

namespace SqLiteEditor.Templates
{
    /// <summary>
    /// Interaction logic for TBrowsWindow.xaml
    /// </summary>
    public partial class TEditWindow : UserControl
    {

        public TEditWindow()
        {
            InitializeComponent();

            SqliteDataGrid.Theme = ExtendedGrid.ExtendedGridControl.ExtendedDataGrid.Themes.Developer;
        }

        private DataTable mDataTable;
        public DataTable DataTable
        {
            get { return mDataTable; }
            set { mDataTable = value; }
        }

        public bool IsDirty
        {
            get
            {
                bool result = false;
                foreach (DataRow Row in DataTable.Rows)
                {
                    result = (Row.RowState == DataRowState.Modified);
                    if (result)
                        break;
                }
                return result;
            }
        }

        public void SetFlowDirection(FlowDirection fd)
        {
            SqliteDataGrid.FlowDirection = fd;
        }

        public void SetFontSize(double fontsize)
        {
            SqliteDataGrid.FontSize = fontsize;
        }

        public void SaveChages()
        {
            SqliteHelper.Update(DataTable);
        }

        
        private void SqliteDataGrid_PreparingCellForEdit(object sender, ExtendedGrid.Microsoft.Windows.Controls.DataGridPreparingCellForEditEventArgs e)
        {
            if (e.EditingElement is TextBox)
                ((TextBox)e.EditingElement).AcceptsReturn = true;
        }
    }
}
